import sqlite3
conn = sqlite3.connect("test.db")
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(20),
password VARCHAR(20)
);
""")
conn.commit()
cursor.execute(
    "INSERT INTO users (name,password) VALUES (?,?)",
    ("张三", "123456")
)
# executemany 插入多条数据
cursor.executemany(
    "INSERT INTO users(name,password) VALUES(?,?)",
    [
        ("李四","7777777"),
        ("王五","66666666")
    ]
)
conn.commit()

# 3.3 查询数据
cursor.execute("SELECT * FROM users;")
# all_user = cursor.fetchmany(2)
# print(type(all_user))
print(cursor)
for row in cursor:
    print(row[1])
print(cursor.description)
print(cursor.lastrowid)

# 4. 关闭连接
cursor.close()
conn.close()
# 提交
